﻿using ERP_RORZE_DLL.Product.Base;
using System;using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;using ERP_RORZE_SYSTEM;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_PRODUCT.Product.database;
using System.Windows.Forms;
using System.Data.SqlClient;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE_DLL.Product.DAO
{
    public class ClsMachineDAO: ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();

        public DataTable GetAllMachine()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllMachine;
            return Execute.DoStoreProcedure(sql, true);
        }
        public DataTable GetAllMachineGroup()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllMachineGroup;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllMachineDailyTime()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.RMachineDailyTime_CrosstabAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void Dostoreprocedure(string store)
        {
            Execute.DoStore(store, true);
        }

        public DataTable Dostoreprocedure1(string store)
        {
            return Execute.DoStoreProcedure(store, true);
        }
        //Machine List
        public DataTable GetMachineByID(MachineTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineID, SqlDbType.NVarChar, b.MachineID)
                    
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionMachine.GetAllMachineByID, parameter, true);
        }   
        public void InsertMachine(MachineTable b)
        { 
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineSP.AccName, SqlDbType.NVarChar, b.AccName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Charge, SqlDbType.Money, b.Charge),
                    CreateParameter(clsConstantsSP.ClsMachineSP.DensanCode, SqlDbType.NVarChar, b.DensanCode),
                    CreateParameter(clsConstantsSP.ClsMachineSP.DensanName, SqlDbType.NVarChar, b.DensanName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Dmachine, SqlDbType.NVarChar, b.Dmachine),
                    CreateParameter(clsConstantsSP.ClsMachineSP.kakokikai, SqlDbType.Bit, b.Kakokikai),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineGR, SqlDbType.NVarChar, b.MachineGR),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineName, SqlDbType.NVarChar, b.MachineName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Maker, SqlDbType.NVarChar, b.Maker),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MakerMachineNo, SqlDbType.NVarChar, b.MakerMachineNo),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MultiPalet, SqlDbType.Bit, b.MultiPalet),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Ratio, SqlDbType.Float, b.Ratio)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMachine.Insert,parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateMachine(MachineTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineSP.AccName, SqlDbType.NVarChar, b.AccName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Charge, SqlDbType.Money, b.Charge),
                    CreateParameter(clsConstantsSP.ClsMachineSP.DensanCode, SqlDbType.NVarChar, b.DensanCode),
                    CreateParameter(clsConstantsSP.ClsMachineSP.DensanName, SqlDbType.NVarChar, b.DensanName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Dmachine, SqlDbType.NVarChar, b.Dmachine),
                    CreateParameter(clsConstantsSP.ClsMachineSP.kakokikai, SqlDbType.Bit, b.Kakokikai),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineGR, SqlDbType.NVarChar, b.MachineGR),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineName, SqlDbType.NVarChar, b.MachineName),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Maker, SqlDbType.NVarChar, b.Maker),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MakerMachineNo, SqlDbType.NVarChar, b.MakerMachineNo),
                    CreateParameter(clsConstantsSP.ClsMachineSP.MultiPalet, SqlDbType.Bit, b.MultiPalet),
                    CreateParameter(clsConstantsSP.ClsMachineSP.Ratio, SqlDbType.Float, b.Ratio)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionMachine.Update, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteMachine(MachineTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineSP.MachineID, SqlDbType.NVarChar, b.MachineID)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionMachine.Delete, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //MachineGroup 
        public DataTable GetMachineGRByID(MachineGroup b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MachineGP, SqlDbType.NVarChar, b.MachineGP)
                    
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionMachineGroup.GetAllMachineGRByID, parameter, true);
        }   

        public void InsertMachineGroup(MachineGroup b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.Content, SqlDbType.NVarChar, b.Content),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MachineGP, SqlDbType.NVarChar, b.MachineGP),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MaQuantiy, SqlDbType.Real, b.MaQuantiy),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MGroupName, SqlDbType.NVarChar, b.MGroupName)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMachineGroup.Insert, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateMachineGroup(MachineGroup b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.Content, SqlDbType.NVarChar, b.Content),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MachineGP, SqlDbType.NVarChar, b.MachineGP),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MaQuantiy, SqlDbType.Real, b.MaQuantiy),
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MGroupName, SqlDbType.NVarChar, b.MGroupName)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionMachineGroup.Update, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteMachineGroup(MachineGroup b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMachineGroupSP.MachineGP, SqlDbType.NVarChar, b.MachineGP)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionMachineGroup.Delete, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Machine Configuration 
        public DataTable GetAllMachineConfiguration()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllMachineConfig;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllMachineConfigurationByID(ClsDataSheetTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.ID, SqlDbType.Int, b.ID)
                    
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionMachine.GetAllMachineConfigByID, parameter, true);
        }

        public void InsertMachineConfiguration(ClsDataSheetTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Loaivl, SqlDbType.NVarChar, b.Loaivl),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.KTP, SqlDbType.NVarChar, b.KTP),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.PageNo, SqlDbType.NVarChar, b.PageNo),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.code, SqlDbType.NVarChar, b.Code),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.StaffRegister, SqlDbType.NVarChar, b.StaffRegister),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Form, SqlDbType.NVarChar, b.Form),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Length, SqlDbType.Float, b.Length),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Width, SqlDbType.Float, b.Width),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.number, SqlDbType.Int, b.Number),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.ConfigureName, SqlDbType.NVarChar, b.ConfigureName),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.KDID, SqlDbType.NVarChar, b.KDID),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.RessionID, SqlDbType.NVarChar, b.RessionID),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.cut, SqlDbType.Bit, b.Cut),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Handl, SqlDbType.Bit, b.Handl),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaTrang, SqlDbType.Bit, b.MaTrang),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaDen, SqlDbType.Bit, b.MaDen),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.HairLine, SqlDbType.Bit, b.HairLine),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Seal, SqlDbType.Bit, b.Seal),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Bafu, SqlDbType.Bit, b.Bafu),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Migaky, SqlDbType.Bit, b.Migaky),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Blast30, SqlDbType.Bit, b.Blast30),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Blast60, SqlDbType.Bit, b.Blast60),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.WashSA, SqlDbType.Bit, b.WashSA),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Helisert, SqlDbType.Bit, b.Helisert),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.SerialClose, SqlDbType.Bit, b.SerialClose),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.VacuumPacked, SqlDbType.Bit, b.VacuumPacked),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.PalCoat, SqlDbType.Bit, b.PalCoat),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Drawn, SqlDbType.Bit, b.Drawn),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaBong, SqlDbType.Bit, b.MaBong),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Casiras, SqlDbType.Bit, b.Casiras),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.InLuoi, SqlDbType.Bit, b.InLuoi)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMachine.InsertMachineConfig, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateMachineConfiguration(ClsDataSheetTable b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Loaivl, SqlDbType.NVarChar, b.Loaivl),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.KTP, SqlDbType.NVarChar, b.KTP),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.PageNo, SqlDbType.NVarChar, b.PageNo),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.date, SqlDbType.DateTime, b.Date),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.code, SqlDbType.NVarChar, b.Code),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.StaffRegister, SqlDbType.NVarChar, b.StaffRegister),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Form, SqlDbType.NVarChar, b.Form),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Length, SqlDbType.Float, b.Length),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Width, SqlDbType.Float, b.Width),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.number, SqlDbType.Int, b.Number),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.ConfigureName, SqlDbType.NVarChar, b.ConfigureName),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.KDID, SqlDbType.NVarChar, b.KDID),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.RessionID, SqlDbType.NVarChar, b.RessionID),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.cut, SqlDbType.Bit, b.Cut),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Handl, SqlDbType.Bit, b.Handl),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaTrang, SqlDbType.Bit, b.MaTrang),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaDen, SqlDbType.Bit, b.MaDen),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.HairLine, SqlDbType.Bit, b.HairLine),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Seal, SqlDbType.Bit, b.Seal),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Bafu, SqlDbType.Bit, b.Bafu),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Migaky, SqlDbType.Bit, b.Migaky),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Blast30, SqlDbType.Bit, b.Blast30),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Blast60, SqlDbType.Bit, b.Blast60),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.WashSA, SqlDbType.Bit, b.WashSA),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Helisert, SqlDbType.Bit, b.Helisert),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.SerialClose, SqlDbType.Bit, b.SerialClose),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.VacuumPacked, SqlDbType.Bit, b.VacuumPacked),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.PalCoat, SqlDbType.Bit, b.PalCoat),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Drawn, SqlDbType.Bit, b.Drawn),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.MaBong, SqlDbType.Bit, b.MaBong),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.Casiras, SqlDbType.Bit, b.Casiras),
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.InLuoi, SqlDbType.Bit, b.InLuoi)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMachine.UpdateMachineConfig, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteMachineConfiguration(ClsDataSheetTable b)
        { 
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsDataSheetSP.ID, SqlDbType.Int, b.ID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMachine.DeleteMachineConfig, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
    }
}
